package com.gzz.orchid.context.application.rbac.convert;

import com.gzz.orchid.context.application.rbac.command.UserSaveCmd;
import com.gzz.orchid.context.application.rbac.pojo.UserDto;
import com.gzz.orchid.context.application.rbac.pojo.UserVo;
import com.gzz.orchid.context.infrastructure.definition.Status;
import com.gzz.orchid.context.infrastructure.persistence.entity.sys.SysUserPo;
import org.mapstruct.*;
import org.mapstruct.factory.Mappers;

import java.util.List;

/**
 * @author higmd
 */
@Mapper(unmappedTargetPolicy = ReportingPolicy.IGNORE, imports = {Status.class})
public interface UserConverter {
    UserConverter INSTANCE = Mappers.getMapper(UserConverter.class);

    @Mappings({
            @Mapping(target = "status", expression = "java(Status.parse(po.getStatus()))")
    })
    UserVo mapVo(SysUserPo po);

    @Mappings({
            @Mapping(target = "status", expression = "java(Status.parse(po.getStatus()))")
    })
    UserDto mapDto(SysUserPo po);

    @Mappings({
            @Mapping(target = "passwd", ignore = true),
            @Mapping(target = "salt", ignore = true)
    })
    void updatePo(@MappingTarget SysUserPo po, UserSaveCmd cmd);
    List<UserDto> mapDtoList(List<SysUserPo> poList);
}
